using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    public partial class GenSubCategoryList : BasePage_SOM
    {
        /// <summary>
        /// Author:SQB
        /// </summary>
        /// 

        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140808";
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(SetLanguage_Click);
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grvData.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
                SetPageLoad();
            }
        }

        void SetLanguage_Click(object sender, EventArgs e)
        {
            SetLanguage();
        }

        private void SetLanguage()
        {
            this.lbl_CodeSetupTitle.Text = this.GetLabel("SOM_CodeSetupGenSubCategoryList");
            this.lblGenSubCategory.Text = this.GetLabel("SOM_GenSubCategory", true);
            this.lblCat.Text = this.GetLabel("SOM_GenCategory", true);
            this.chkVoid.Text = this.GetLabel("SOM_Voided");
            this.btnSearch.Text = this.GetLabel("COM_Search");
            this.btnAddNew.Text = this.GetLabel("SOM_AddNewAssetLoanItem");
            this.lblDisplay.Text = this.GetLabel("COM_Show", true);

            BindGenCategory();
            if (this.Request["GenCategoryID"] != null)
            {
                BindData(true);
            }
            else
            {
                BindData(false);
            }
        }

        private void BindGenCategory()
        {
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDGenCategory.GetGenCategory(this.LangCode, "", true);

            this.ddlGenCategory.Items.Clear();
            this.ddlGenCategory.DataSource = dt;
            this.ddlGenCategory.DataValueField = "GenCategoryID";
            this.ddlGenCategory.DataTextField = "Description";
            this.ddlGenCategory.DataBind();
            this.ddlGenCategory.Items.Insert(0, LiALL());
            this.ddlGenCategory.SelectedIndex = 0;


            dt.Dispose();
            dt = null;
        }

        private void SetPageLoad()
        {
            if (this.Request["GenCategoryID"] != null)
            {
                this.ddlGenCategory.SelectedValue = this.Request["GenCategoryID"].ToString();
            }   
        }

        private void BindData(bool loadFromGenCategory)
        {
            DataTable dt = new DataTable();
            if (loadFromGenCategory == true)
            {
                dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDGenSubCategory.GetGenSubCategoryByGenCategoryID(this.LangCode, int.Parse(this.Request["GenCategoryID"].ToString()));
                this.chkVoid.Checked = true;
            }
            else
            {
                dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDGenSubCategory.GetGenSubCategory(this.LangCode, int.Parse(this.ddlGenCategory.SelectedValue), this.txtGenSubCategory.Text.Trim(), this.chkVoid.Checked);
            }
            this.grvData.DataSource = dt.DefaultView;
            this.grvData.DataBind();
        }

        #region Event
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData(false);
        }

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("GenSubCategoryEntry.aspx");
        }
        #endregion

        protected void grvData_NeedDataBind()
        {
            BindData(false);
        }

        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((HyperLink)e.Row.Cells[5].FindControl("hypEdit")).NavigateUrl = "GenSubCategoryEntry.aspx?GenSubCategoryID=" + this.grvData.DataKeys[e.Row.RowIndex]["GenSubCategoryID"].ToString();
                ((HyperLink)e.Row.Cells[5].FindControl("hypEdit")).ToolTip = this.GetLabel("SOM_GenSubCategoryEntry");
            }
        }

    }
}
